<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="状态" prop="status">
        <el-select v-model="queryParams.status" placeholder="请选择状态" clearable @keyup.enter.native="handleQuery">
          <el-option label="取消借阅" value="-1" />
          <el-option label="借阅中" value="0" />
          <el-option label="被退回" value="1" />
          <el-option label="已归还" value="2" />
          <el-option label="已逾期" value="3" />
          <el-option label="申请中" value="4" />
          <el-option label="部分归还" value="5" />
        </el-select>
      </el-form-item>
      <el-form-item label="借阅天数" prop="borrowDays">
        <el-select v-model="queryParams.borrowDays" placeholder="请选择" clearable label-width="68px"
          @keyup.enter.native="handleQuery">
          <el-option v-for="dict in dict.type.JYTS" :key="dict.value" :label="dict.label" :value="dict.value" />
        </el-select>
      </el-form-item>
      <el-form-item label="利用目的" prop="yongtu">
        <el-select v-model="queryParams.yongtu" placeholder="请选择" clearable label-width="68px"
          @keyup.enter.native="handleQuery">
          <el-option v-for="dict in dict.type.LYMD" :key="dict.value" :label="dict.label" :value="dict.value" />
        </el-select>
        <!-- <el-input
          v-model="queryParams.yongtu"
          placeholder="请输入利用目的"
          clearable
          @keyup.enter.native="handleQuery"
        />-->
      </el-form-item>
      <el-form-item label="申请时间">
        <el-date-picker v-model="daterangeCreateTime" style="width: 240px" value-format="yyyy-MM-dd HH:mm:ss"
          type="daterange" range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期"></el-date-picker>
      </el-form-item>
      <!--<el-form-item label="档案类型" prop="daType">
        <el-input
          v-model="queryParams.daType"
          placeholder="请输入档案类型"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>-->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-row :gutter="10" class="mb8">
      <!--
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"

          @click="handleAdd"
          v-hasPermi="['archive:archiveBorrow:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"

          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['archive:archiveBorrow:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"

          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['archive:archiveBorrow:remove']"
        >删除</el-button>
      </el-col>-->
      <el-col :span="1.5">
        <!--<el-button
          type="warning"
          plain
          icon="el-icon-download"

          @click="handleExport"
          v-hasPermi="['archive:archiveBorrow:export']"
        >导出</el-button>-->
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="archiveBorrowList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <!--<el-table-column label="借阅单ID" align="center" prop="borrowId" />-->
      <el-table-column label="状态" align="center" prop="status">
        <template slot-scope="scope">
          <span>{{ scope.row.status == -1 ? "取消借阅"
            : scope.row.status == 0 ? "借阅中"
              : scope.row.status == 1 ? "被退回"
                : scope.row.status == 2 ? "已归还"
                  : scope.row.status == 3 ? "已逾期"
                    : scope.row.status == 4 ? "申请中"
                      : "未知" }}</span>
        </template>
      </el-table-column>
      <el-table-column label="借阅人" align="center" prop="borrowUser">
        <template slot-scope="scope">


          <span>{{ getDeptUserMap(scope.row.borrowUser) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="借阅单位" align="center" prop="borrowDept">
        <template slot-scope="scope">
          <span>{{ getDeptUserMap(scope.row.borrowDept) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="借阅天数" align="center" prop="borrowDays">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.JYTS" :value="scope.row.borrowDays" />
        </template>
      </el-table-column>
      <el-table-column label="利用目的" align="center" prop="yongtu">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.LYMD" :value="scope.row.yongtu" />
        </template>
      </el-table-column>
      <el-table-column label="利用方式" align="center" prop="liyongfangshi">
        <template slot-scope="scope">
          {{ scope.row.liyongfangshi == 1 ? "复印件" : '原件' }}
        </template>
      </el-table-column>
      <el-table-column label="借阅类型" align="center" prop="daType">
        <template slot-scope="scope">
          <span>{{ scope.row.daType == 'F' ? "实体件" : scope.row.daType == 'E' ? "电子件" : "未知" }}</span>
        </template>
      </el-table-column>
      <el-table-column label="备注" align="center" prop="beizhu" :show-overflow-tooltip="true" />
      <el-table-column label="申请时间" align="center" prop="createTime" width="180">
        <template slot-scope="scope">
          <span>{{ formattedTime(scope.row.createTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="创建人" align="center" prop="creater">
        <template slot-scope="scope">
          <span>{{ getDeptUserMap(scope.row.creater) }}</span>
        </template>
      </el-table-column>
      <!--      <el-table-column label="创建单位" align="center" prop="createDept" >
        <template slot-scope="scope">
          <span>{{ getDeptUserMap(scope.row.createDept) }}</span>
        </template>
      </el-table-column>
     &lt;!&ndash; <el-table-column label="经办人" align="center" prop="jingBanRen" />
      <el-table-column label="利用方式" align="center" prop="liyongfangshi" />&ndash;&gt;
      <el-table-column label="登记人" align="center" prop="dengJiRen"  >
        <template slot-scope="scope">
          <span>{{ getDeptUserMap(scope.row.dengJiRen) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="登记单位" align="center" prop="dengJiDept"  >
        <template slot-scope="scope">
          <span>{{ getDeptUserMap(scope.row.dengJiDept) }}</span>
        </template>
      </el-table-column>-->
      <el-table-column label="登记时间" align="center" prop="dengJiTime">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.dengJiTime, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
      <el-table-column label="开始时间" align="center" prop="startTime">
        <template slot-scope="scope">
          <span>{{ formattedTime(scope.row.startTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="结束时间" align="center" prop="endTime">
        <template slot-scope="scope">
          <span>{{ formattedTime(scope.row.endTime) }}</span>
        </template>
      </el-table-column>
      <!--<el-table-column label="档案类型" align="center" prop="daType" />-->
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">

          <!-- isReceive 0 未领取  1领取过了 scope.row.daType == 'F'   scope.row.status == 0 借阅中-->
<!--          实体档案流程审批结束后展示 领取按钮-->
          <el-button type="text" icon="el-icon-document" @click="handlelqTap(scope.row)"
            v-hasPermi="['archive:archiveBorrow:receive']"
            v-if="scope.row.daType == 'F' && scope.row.isReceive != 1 && scope.row.status == 0 ">领取</el-button>
          <el-button type="text" icon="el-icon-document" v-if="scope.row.daType == 'F' && scope.row.isReceive == 1"
            v-hasPermi="['archive:archiveBorrow:receive']">已领取</el-button>
          <el-button type="text" icon="el-icon-document" @click="handledeitleJY(scope.row)"
            v-hasPermi="['archive:archiveBorrow:query']">查看借阅详情</el-button>
          <el-button type="text" @click="handlechtap(scope.row)" v-hasPermi="['archive:archiveBorrowCar:cuiHuanBtn']"
            v-show="scope.row.status == '3' || scope.row.status == '5'">催还</el-button>
          <el-button type="text" icon="el-icon-document" @click="handleUpdate(scope.row)"
            v-hasPermi="['archive:archiveBorrow:query']">查看详情</el-button>
          <el-button type="text" icon="el-icon-edit" @click="handleUpdateReturn(scope.row)" v-hasPermi="['archive:archiveBorrow:edit']"
            v-show="((scope.row.status == '0' || scope.row.status == '3') && scope.row.daType == 'F')">归还</el-button>

          <el-button type="text" icon="el-icon-edit" @click="handleCancelProcess(scope.row)"
            v-show="scope.row.status == '4'" v-hasPermi="['archive:archiveBorrow:quxiao']">取消借阅</el-button>

          <template>
            <el-button v-if="scope.row.feedbackId != undefined" type="text" icon="el-icon-document"
              @click="feedtap(scope.row)" v-hasPermi="['archive:archiveBorrow:lyfk']">反馈详情</el-button>
            <el-button v-else type="text" icon="el-icon-edit-outline" @click="feedtap(scope.row)"
              v-hasPermi="['archive:archiveBorrow:lyfk']">利用效果反馈</el-button>
          </template>
          <template>

            <el-button v-if="scope.row.csatState == 1" type="text" icon="el-icon-document" @click="rateTap(scope.row)"
              v-hasPermi="['archive:archiveBorrow:pj']">评价详情</el-button>
            <el-button v-else type="text" icon="el-icon-edit" @click="rateTap(scope.row)"
              v-hasPermi="['archive:archiveBorrow:pj']">满意度评价</el-button>
          </template> <!--<el-button

            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['archive:archiveBorrow:remove']"
          >删除</el-button>-->
          <el-button type="text" icon="el-icon-edit" @click="handleUpdateBorrowDaysOpen(scope.row)"
            v-show="scope.row.status == '3'" v-hasPermi="['archive:archiveBorrow:edit']">续借</el-button>
          <el-dropdown size="mini" @command="(command) => handleCommand(command, scope.row)"
            v-hasPermi="['archive:archiveBorrow:download']">
            <el-button size="mini" type="text" icon="el-icon-d-arrow-right">更多</el-button>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item command="downloadWaxPaper" icon="el-icon-circle-check">下载蜡纸底图调用单</el-dropdown-item>
              <el-dropdown-item command="downloadArchiveBorrow" icon="el-icon-user">下载档案（资料）借阅登记表</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />


    <el-dialog title="续借条件" :visible.sync="dialogFormVisible" width="100" :center="true">

      <el-form :model="form" :rules="xboorowRules" ref="xboorowrulesForm" label-width="100px" class="demo-ruleForm">
        <el-form-item label="续借天数" prop="borrowDays">
          <el-select v-model="form.borrowDays" placeholder="请选择续借天数">
            <el-option label="一天" value="1"></el-option>
            <el-option label="三天" value="3"></el-option>
            <el-option label="五天" value="5"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="利用目的" prop="yongtu">
          <el-select v-model="form.yongtu" placeholder="请选择" clearable label-width="68px"
            @keyup.enter.native="handleQuery">
            <el-option v-for="dict in dict.type.LYMD" :key="dict.value" :label="dict.label" :value="dict.value" />
          </el-select>
        </el-form-item>


      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button  @click="closeDelDialogBorrow">取 消</el-button>
        <el-button type="primary" @click="handleUpdateBorrowDays">确 定</el-button>
      </div>
    </el-dialog>

    <!-- 添加或修改archiveBorrow对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="1000px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <!--<el-form-item label="状态" prop="status">
          <el-input v-model="form.status" placeholder="请输入状态" />
        </el-form-item>
        <el-form-item label="借阅天数" prop="borrowDays">
          <el-input v-model="form.borrowDays" placeholder="请输入借阅天数" />
        </el-form-item>
        <el-form-item label="利用目的" prop="yongtu">
          <el-input v-model="form.yongtu" placeholder="请输入利用目的" />
        </el-form-item>
        <el-form-item label="档案类型" prop="daType">
          <el-input v-model="form.daType" placeholder="请输入档案类型" />
        </el-form-item>-->
        <!--<el-divider content-position="center">archiveBorrowItem信息</el-divider>-->
        <el-row :gutter="10" class="mb8">
          <!-- <el-col :span="1.5">
            <el-button type="primary" icon="el-icon-plus"  @click="handleAddYqdaborrowItem">添加</el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button type="danger" icon="el-icon-delete"  @click="handleDeleteYqdaborrowItem">删除</el-button>
          </el-col> -->


          <el-col :span="1.5" v-if="upadteRow.status=='0'">
              <el-button type="primary" plain icon="el-icon-download" v-hasPermi="['archive:jyjl:allDownload']"
                @click="allDownloadTap">批量下载</el-button>
            </el-col>

        </el-row>
        <el-table :data="yqdaborrowItemList" :row-class-name="rowYqdaborrowItemIndex"
          @selection-change="handleYqdaborrowItemSelectionChange" ref="yqdaborrowItem" @cell-dblclick="celldblclick">
          <el-table-column type="selection" width="50" align="center" />
          <el-table-column label="序号" align="center" prop="index" width="50" />
          <el-table-column label="状态" align="center" prop="status">
            <template slot-scope="scope">
              <span>{{ scope.row.status == -1 ? "取消借阅"
                : scope.row.status == 0 ? "借阅中"
                  : scope.row.status == 1 ? "被退回"
                    : scope.row.status == 2 ? "已归还"
                      : scope.row.status == 3 ? "已逾期"
                        : scope.row.status == 4 ? "申请中"
                          : "未知" }}</span>
            </template>
          </el-table-column>
          <!-- <el-table-column label="返回时间" align="center" prop="returnStatus" />
          -<el-table-column label="档案Id" align="center" prop="daId" />
           <el-table-column label="门类ID" align="center" prop="categoryId" />
           <el-table-column label="子表名称" align="center" prop="subTableName" />-->
          <el-table-column label="档案(项目)标题" align="center" prop="archiveData.TITLE,archiveData.XMMC">
            <template slot-scope="scope">
              {{ scope.row.archiveData.TITLE == undefined ? scope.row.archiveData.XMMC : scope.row.archiveData.TITLE }}
            </template>
          </el-table-column>
          <el-table-column label="全宗号" align="center" prop="archiveData.QZH" />
          <el-table-column label="档号" align="center" prop="archiveData.DH" />
          <el-table-column label="日期" align="center" prop="archiveData.RQ" />
          <!--<el-table-column label="状态" prop="status" width="150">
            <template slot-scope="scope">
              <el-input v-model="scope.row.status" placeholder="请输入状态" />
            </template>
          </el-table-column>
          <el-table-column label="返回时间" prop="returnStatus" width="240">
            <template slot-scope="scope">
              <el-date-picker clearable v-model="scope.row.returnStatus" type="date" value-format="yyyy-MM-dd" placeholder="请选择返回时间" />
            </template>
          </el-table-column>
          <el-table-column label="门类ID" prop="status" width="150">
            <template slot-scope="scope">
              <el-input v-model="scope.row.categoryId" placeholder="请输入状态" />
            </template>
          </el-table-column>
          <el-table-column label="子表名称" prop="status" width="150">
            <template slot-scope="scope">
              <el-input v-model="scope.row.subTableName" placeholder="请输入状态" />
            </template>
          </el-table-column>
          <el-table-column label="档案Id" prop="档案Id" width="150">
            <template slot-scope="scope">
              <el-input v-model="scope.row.daId" placeholder="请输入状态" />
            </template>
          </el-table-column>-->
        </el-table>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <!-- <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>-->
      </div>
    </el-dialog>


    <!--start  组件详情 -->
    <jianDetailsOpen v-if="jianDetailsOpen" :open="jianDetailsOpen" :borrowItemId="borrowItemId" :celldbData="celldbData"
      @detailsHandleClose="detailsHandleClose">
    </jianDetailsOpen>
    <!--end 组件详情 -->
    <!-- start 组卷\项目详情 -->
    <juanDetailsOpen v-if="juanDetailsOpen" :open="juanDetailsOpen" :celldbData="celldbData" :borrowItemId="borrowItemId"
      @detailsHandleClose="detailsHandleClose"></juanDetailsOpen>
    <!-- end 组卷\项目详情 -->
    <el-dialog v-if="openCk" title="催还" :visible.sync="openCk" width="30%" append-to-body :before-close="closeDelDialog">
      <el-input type="textarea" :autosize="{ minRows: 2, maxRows: 5 }" placeholder="请尽快归还档案!" v-model="msg" maxlength="30"
        show-word-limit>
      </el-input>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFormCh">确 定</el-button>
        <el-button @click="closeDelDialog">取 消</el-button>
      </div>
    </el-dialog>
    <!-- start 利用反馈 -->
    <Feedback v-if="feedbackOpen" :feedbackOpen="feedbackOpen" @closeDelDialogFeedback="closeDelDialogFeedback"
      :dataRow="dataRow" @submitFormFeedback="submitFormFeedback">
    </Feedback>
    <!-- end 利用反馈 -->
    <!-- start 满意度评价 -->
    <rate v-if="rateOpen" :rateOpen="rateOpen" @closeDelDialogRate="closeDelDialogRate" :dataRow="dataRow"
      @submitFormRate="submitFormRate"></rate>
    <!-- end 满意度评价 -->
    <!-- start 借阅详情 -->
    <detailVue v-if="isDetailOpen" :isDetailOpen="isDetailOpen" @closeDelDialogjyxq="closeDelDialogjyxq"
      :dataRow="dataRow"></detailVue>
    <!-- end 借阅详情 -->
  </div>
</template>

<script>

import { listArchiveBorrow, getArchiveBorrow, delArchiveBorrow, addArchiveBorrow, updateArchiveBorrow, updateArchiveBorrowDays, downloadWaxPaperDocx, downloadArchiveBorrowTable, cuiHuan, receiveBorrowId } from "@/api/archive/archiveBorrow/archiveBorrow";
import { getLastIndexOf } from "@/utils";
import jianDetailsOpen from '@/components/componentsJianDetails/index.vue' //件详情
import juanDetailsOpen from '@/components/componentsJuanDetails/index.vue'
import { cancelProcess, deptUserTree } from "../../../api/archive/archiveBorrow/archiveBorrow";
import { getthbytreenodeHeaderList } from "@/api/archive/fileCollection/archiveApproval"; //卷详情
import Feedback from "@/components/Feedback";
import rate from "@/components/rate"
import detailVue from "@/views/archive/archiveBorrow/detail.vue"
export default {
  archive_Dicts: ['LYMD', 'JYTS'], // 利用目的字典项
  name: "ArchiveBorrow",
  components: {
    jianDetailsOpen,
    juanDetailsOpen,
    Feedback,
    rate,
    detailVue
  },
  data() {
    return {
      isDetailOpen: false,//借阅详情
      rateOpen: false,
      feedbackOpen: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 子表选中数据
      checkedYqdaborrowItem: [],

      checkedYqdaborrowItemsingle:true,
      checkedYqdaborrowItemmultiple:true,
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      deptUserMap: {},
      // 总条数
      total: 0,
      // archiveBorrow表格数据
      archiveBorrowList: [],
      // archiveBorrowItem表格数据
      yqdaborrowItemList: [],
      //弹出层隐藏
      dialogFormVisible: false,
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 续借次数时间范围
      daterangeCreateTime: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        status: null,
        borrowDays: null,
        yongtu: null,
        beizhu: null,
        createTime: null,
        creater: null,
        createDept: null,
        jingBanRen: null,
        liyongfangshi: null,
        dengJiRen: null,
        dengJiDept: null,
        dengJiTime: null,
        startTime: null,
        endTime: null,
        branchCode: null,
        entryId: null,
        daType: null
      },
      // 表单参数
      form: {
        borrowDays:undefined,
        yongtu:undefined,
      },
      // 表单校验
      rules: {
      },
      xboorowRules: {

        borrowDays: [
          { required: true, message: '请选择借阅天数', trigger: 'change' }
        ],
        yongtu: [
          { required: true, message: '请选择利用目的', trigger: 'change' }
        ],
      },
      jianDetailsOpen: false,//件详情弹窗
      juanDetailsOpen: false,//卷详情弹窗
      // 借阅单id
      borrowIds: undefined,
      borrowItemId: undefined,
      openCk: false,
      msg: "请尽快归还档案",
      dataRow: undefined,
      upadteRow:"",
      selectionString:[]
    };
  },
  mounted() {
    debugger
    // 在页面加载时，获取路由传递的查询参数
    this.queryParams.status = this.$route.query.status || '';
    console.log('this.queryParams.status :>> ', this.queryParams.status);
    this.getList()
  },
  created() {
    this.getDeptUserTree()
  },
  filters: {
  },
  methods: {


      //批量下载
      allDownloadTap() {
      var that = this;


      if (!this.checkedYqdaborrowItemmultiple) {

        var data = [];
        for (var i in this.selectionString) {
          data.push({
            "subtablename": this.selectionString[i].subTableName,
            "id": this.selectionString[i].daId
          })


        }



          var dalist={
            dalist:data
          }
         var dalist= JSON.stringify(dalist)
              this.download('/archive/list/query/download/electronics', {dalist}
            , `wjb_${new Date().getTime()}.zip`)



      } else {
        this.$modal.msgWarning('请选择下载数据哦！')
      }


    },
    //关闭
    closeDelDialogjyxq() {
      this.isDetailOpen = false
    },
    //查看借阅详情
    handledeitleJY(row) {
      this.dataRow = row
      this.isDetailOpen = true
    },
    //领取
    handlelqTap(row) {
      var that = this;
      this.$modal.confirm('是否确定领取？').then((res) => {
        receiveBorrowId(row.borrowId).then(res => {
          if (res.code == "200") {
            if (res.msg == "成功") {
              that.$modal.msgSuccess(res.msg);
              that.getList();
            } else {
              this.$message({ message: res.msg, type: 'warning' })
            }


          }
        })

      }).catch(() => {

      });

    },


    formattedTime(value) {
      // 格式化日期，你可以使用任何适合你的格式
      if (value == null || value == undefined || value == '') {
        return null;
      }
      const dt = new Date(value);
      //return date.toLocaleString(); // 返回格式化后的日期字符串
      let year = dt.getFullYear();
      let month = (dt.getMonth() + 1).toString().padStart(2, '0');
      let date = dt.getDate().toString().padStart(2, '0');
      let hour = dt.getHours().toString().padStart(2, '0');
      let minute = dt.getMinutes().toString().padStart(2, '0');
      let second = dt.getSeconds().toString().padStart(2, '0');
      return `${year}-${month}-${date} ${hour}:${minute}:${second}`;

    },
    async getDeptUserTree() {
      await deptUserTree().then(response => {
        let deptUserTree = response.data;
        this.deptUserMap = new Map();
        this.deptUserMap = this.convertToMap(deptUserTree);
        console.log(this.deptUserMap);
      })
    },
    getDeptUserMap(userId) {
      if (this.deptUserMap[userId] == null || this.deptUserMap[userId] == undefined) {
        return userId;
      } else {
        return this.deptUserMap[userId];
      }
    },
    // 更多操作触发
    handleCommand(command, row) {
      switch (command) {
        case "downloadWaxPaper":
          this.downloadWaxPaper(row);
          break;
        case "downloadArchiveBorrow":
          this.downloadArchiveBorrow(row);
          break;
        default:
          break;
      }
    },
    downloadWaxPaper(row) {
      downloadWaxPaperDocx(row).then((res) => {
        // 创建一个 Blob 对象，用于存储二进制数据
        if (res.data.result == "fail") {
          this.$message({ message: res.data.msg, type: 'warning' })
        } else {
          window.open(res.data.url);
        }
        /*const blob = new Blob([response], { type: "application/octet-stream" });

        // 创建一个下载链接
        const url = window.URL.createObjectURL(blob);

        // 创建一个 <a> 元素并设置下载链接
        const link = document.createElement('a');
        link.href = url;
        link.download = '蜡纸底图调用单.docx'; // 设置下载的文件名

        // 模拟点击 <a> 元素来触发下载
        link.click();

        // 释放资源
        window.URL.revokeObjectURL(url);
        })
        .catch((error) => {
          console.error('下载文件时出错：', error);*/
      });
    },
    downloadArchiveBorrow(row) {
      downloadArchiveBorrowTable(row).then((res) => {
        // 创建一个 Blob 对象，用于存储二进制数据
        if (res.data.result == "fail") {
          this.$message({ message: res.data.msg, type: 'warning' })
        } else {
          window.open(res.data.url);
        }
        /*const blob = new Blob([response], { type: "application/octet-stream" });

        // 创建一个下载链接
        const url = window.URL.createObjectURL(blob);

        // 创建一个 <a> 元素并设置下载链接
        const link = document.createElement('a');
        link.href = url;
        link.download = '档案（资料）借阅登记表.docx'; // 设置下载的文件名

        // 模拟点击 <a> 元素来触发下载
        link.click();

        // 释放资源
        window.URL.revokeObjectURL(url);
        })
        .catch((error) => {
          console.error('下载文件时出错：', error);
        */
      });
    },

    convertToMap(data) {
      const map = new Map();

      data.forEach(item => {
        map[item.id] = item.label;
        if (item.children) {
          const childMap = this.convertToMap(item.children);
          Object.assign(map, childMap);
        }
        if (item.userChildren) {
          const userChildMap = this.convertToMap(item.userChildren);
          Object.assign(map, userChildMap);
        }
      });

      return map;
    },
    /** 查询archiveBorrow列表 */
    getList() {
      this.loading = true;
      this.queryParams.params = {};
      if (null != this.daterangeCreateTime && '' != this.daterangeCreateTime) {
        this.queryParams.params["beginCreateTime"] = this.daterangeCreateTime[0];
        this.queryParams.params["endCreateTime"] = this.daterangeCreateTime[1];
      }
      listArchiveBorrow(this.queryParams).then(response => {
        this.archiveBorrowList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        borrowId: null,
        borrowNo: null,
        status: null,
        borrowUser: null,
        borrowDept: null,
        borrowDays: null,
        yongtu: null,
        beizhu: null,
        createTime: null,
        creater: null,
        createDept: null,
        jingBanRen: null,
        liyongfangshi: null,
        dengJiRen: null,
        dengJiDept: null,
        dengJiTime: null,
        startTime: null,
        endTime: null,
        branchCode: null,
        entryId: null,
        daType: null
      };
      this.yqdaborrowItemList = [];
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.daterangeCreateTime = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.borrowId)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加archiveBorrow";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {

      console.log(row,"----------------------------------")
      this.upadteRow=row;
      this.reset();
      const borrowId = row.borrowId || this.ids
      getArchiveBorrow(borrowId).then(response => {
        this.form = response.data;
        this.yqdaborrowItemList = response.data.yqdaborrowItemList;
        this.open = true;
        this.borrowIds = borrowId
        this.title = "查看借阅详情";
      });
    },
    handleUpdateReturn(row) {
      this.form.borrowId = row.borrowId;
      this.form.status = "2";
      this.form.startTime = row.startTime;
      this.form.endTime = new Date();
      const borrowId = row.borrowId || this.ids
      getArchiveBorrow(borrowId).then(response => {
        //this.form = response.data;
        this.yqdaborrowItemList = response.data.yqdaborrowItemList;
        this.form.yqdaborrowItemList = response.data.yqdaborrowItemList;
        for (const yqdaborrowItemListKey in this.yqdaborrowItemList) {

        }
        //this.open = true;
        this.borrowIds = borrowId
        //this.title = "查看借阅详情";
        console.log(this.form, "xxxxx")
        updateArchiveBorrow(this.form).then(response => {
          this.$modal.msgSuccess("修改成功");
          this.open = false;
          this.getList();
        });
      });

    },
    handleUpdateBorrowDaysOpen(row) {
      this.form.borrowId = row.borrowId;
      this.dialogFormVisible = true;
    },
    handleUpdateBorrowDays() {
      this.$refs['xboorowrulesForm'].validate((valid) => {
        if (valid) {
          updateArchiveBorrowDays(this.form).then(response => {
            this.$modal.msgSuccess("操作成功");
            this.dialogFormVisible = false;
            this.getList();
          });
        } else {
          console.log('error submit!!');
          return false;
        }
      });



    },
    handleCancelProcess(row) {
      this.reset();
      const borrowId = row.borrowId || this.ids
      cancelProcess(borrowId).then(response => {
        if (response.code == 200) {
          this.$modal.msgSuccess("取消借阅成功");
          this.getList();
        }
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          this.form.yqdaborrowItemList = this.yqdaborrowItemList;
          if (this.form.borrowId != null) {
            updateArchiveBorrow(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addArchiveBorrow(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const borrowIds = row.borrowId || this.ids;
      this.$modal.confirm('是否确认删除所选数据项？').then(function () {
        return delArchiveBorrow(borrowIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => { });
    },
    /** archiveBorrowItem序号 */
    rowYqdaborrowItemIndex({ row, rowIndex }) {
      row.index = rowIndex + 1;
    },
    /** archiveBorrowItem添加按钮操作 */
    handleAddYqdaborrowItem() {
      let obj = {};
      obj.daId = "";
      obj.status = "";
      obj.returnStatus = "";
      obj.startTime = "";
      obj.endTime = "";
      obj.daGdsj = "";
      obj.daGdcs = "";
      obj.borrowUser = "";
      obj.isAgree = "";
      obj.secClassification = "";
      obj.GUIHUANTIME = "";
      obj.state = "";
      obj.daFloderMark = "";
      obj.feedBack = "";
      obj.downloadable = "";
      obj.printable = "";
      obj.permitDownloadCount = "";
      obj.downloadCount = "";
      obj.printCount = "";
      obj.xujiecishu = "";
      this.yqdaborrowItemList.push(obj);
    },
    /** archiveBorrowItem删除按钮操作 */
    handleDeleteYqdaborrowItem() {
      if (this.checkedYqdaborrowItem.length == 0) {
        this.$modal.msgError("请借阅后再浏览！");
      } else {
        const yqdaborrowItemList = this.yqdaborrowItemList;
        const checkedYqdaborrowItem = this.checkedYqdaborrowItem;
        this.yqdaborrowItemList = yqdaborrowItemList.filter(function (item) {
          return checkedYqdaborrowItem.indexOf(item.index) == -1
        });
      }
    },
    /** 复选框选中数据 */
    handleYqdaborrowItemSelectionChange(selection) {
      this.checkedYqdaborrowItem = selection.map(item => item.index)
      this.checkedYqdaborrowItemsingle = selection.length !== 1
      this.checkedYqdaborrowItemmultiple = !selection.length
      this.selectionString = selection
      console.log(this.selectionString,"-----------------------------------")
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('archive/archiveBorrow/export', {
        ...this.queryParams
      }, `archiveBorrow_${new Date().getTime()}.xlsx`)
    },

    //双击列表进入详情页面
    celldblclick(row) {
      this.borrowItemId = row.itemId
      if (row.status == '0' && row.state == '0') {
        this.$modal.msgWarning('实体件借阅后请去线下领取')
      }
      if (row.status == 0) {
        var level = "";
        if (getLastIndexOf(row.subTableName) == "F") {  //F 件
          level = 0
        } else if (getLastIndexOf(row.subTableName) == "V") { //卷
          level = 1
        } else { //项目
          level = 3
        }

        getthbytreenodeHeaderList(
          {
            categoryId: row.categoryId, menuId: this.$route.meta.menuId, subTableName: row.subTableName
          }
        ).then(response => {
          var tableHeaderList = response.rows
          this.celldbData = {
            id: row.daId,
            categoryId: row.categoryId,
            menuId: this.$route.meta.menuId,
            sub_table_name: row.subTableName,
            label: row.archiveData.TITLE,
            level: level,
            ifSub_table_name: row.subTableName,
            borrowId: this.borrowIds, // 判断是复制单数据还是其他数据  复制单需要传递  其他数据不需要传递
            tableHeaderList: tableHeaderList,
            isDel: "0",  //判断是回收站数据还是接收收据 isDel:1  回收站    isDel:0 //离线接收、档案接收、在线接收
            isShowjieyue: true,//借阅中

            borrowIdofd: "1" //借阅ofd预览
          }


          this.$nextTick(() => {
            if (getLastIndexOf(row.subTableName) == "F") {  //F 进入件详情
              this.jianDetailsOpen = true;
            } else { //进入卷详情 和项目详情
              this.juanDetailsOpen = true
            }
          })
        })
      } else {
        this.$message({ message: "只有借阅中的档案数据才可以查看详情哦！", type: 'warning' })
      }
    },
    //关闭详情页面
    detailsHandleClose() {
      this.jianDetailsOpen = false;
      this.juanDetailsOpen = false;
    },
    //催化
    handlechtap(row) {
      var that = this;
      this.dataRow = row;
      this.openCk = true;


    },

    closeDelDialog() {
      this.openCk = false;
      this.msg = '请尽快归还档案'
    },
    closeDelDialogRate() {
      this.rateOpen = false;
    },
    closeDelDialogFeedback() {
      this.feedbackOpen = false;
    },
    closeDelDialogjyxq() {
      console.log("klsdjfklsdjflksdjfklsdjfklsdjfkl")
      this.isDetailOpen = false;
    },
    closeDelDialogBorrow(){

      this.$refs["xboorowrulesForm"].resetFields();
      this.dialogFormVisible=false
    },

    //催还提交
    submitFormCh() {
      cuiHuan({
        msg: this.msg,
        id: this.dataRow.borrowId
      }).then(res => {
        console.log(res)
        if (res.code == "200") {
          this.$modal.msgSuccess("操作成功");
          this.openCk = false;
          this.getList();
          this.msg = "请尽快归还档案"
        }
      }).catch(res => {
        this.msg = '请尽快归还档案'
      })
    },

    //利用效果反馈
    feedtap(row) {
      var that = this;
      this.dataRow = row
      this.feedbackOpen = true
    },

    //利用效果反馈chengg
    submitFormFeedback() {
      this.feedbackOpen = false;
      this.getList();
    },

    //满意度评价
    rateTap(row) {
      var that = this;
      this.dataRow = row
      that.rateOpen = true;
    },

    submitFormRate() {
      this.rateOpen = false;
      this.getList();
    }
  }
};
</script>
